﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;



public partial class 反射对象__传入类型名得到这个类型名的实例 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Type t = Type.GetType("Test");
        //System.Reflection.ConstructorInfo ctor = t.GetConstructor(System.Type.EmptyTypes);
        //Test test = (Test)ctor.Invoke(null);
        //Console.WriteLine(test.Method("aa"));
        //object o = Activator.CreateInstance(Type.GetType("Test"));
        // Response.Write(((Test)o).Method("aa"));

        //test1
        Type pp = Type.GetType("Test");
       if(pp!=null)
       {

        object o = System.Activator.CreateInstance(pp);
        Response.Write(((Test)o).Method("aaa"));
       }
        //test2
    }

    public class Test
    {
        public string Method(string s)
        {
            return s.ToUpper();
        }
    }
    public class pDemo
    {
        public void main()
        {
            Type t = Type.GetType("Test");
            System.Reflection.ConstructorInfo ctor = t.GetConstructor(System.Type.EmptyTypes);
            Test test = (Test)ctor.Invoke(null);
            Console.WriteLine(test.Method("aa"));

            object o = Activator.CreateInstance(Type.GetType("Test"));
            Console.WriteLine(((Test)o).Method("aa"));
        }
    }


}
